library(tidyverse)
library(readxl)

asylum = read_excel("asylum.xls")

asylum = asylum %>% 
  gather(year, value, -state, -measure)

asylum$measure = asylum$measure %>%
  str_replace("app", "Asylum Applications") %>%
  str_replace("posdec", "Positive Decisions") %>%
  factor(levels = c("Asylum Applications", "Positive Decisions"))


asylum %>%
  filter(year %in% 2014:2017, state %in% c("Germany", "Austria")) %>%
  ggplot(aes(x = year, # Year on x axis
             y = value, # Applications and Positive Decisions on y axis
             shape = state, # Different point shapes for each country
             color = state, # Different line types by country
             group = state)) + 
  geom_point(size = 2) + # Add points with larger size
  geom_line() + # Add lines
  facet_grid(measure ~ .,
             switch = "y",
             scales = "free_y") + # Stacks plots based on measure type
  expand_limits(y = 0) + # Ensure y axis includes 0
  scale_x_discrete(expand = expand_scale(mult = .05, add = 0)) +
  scale_shape_discrete(solid = F) + # Use hollow point shapes
  scale_color_grey(start = 0, end = 0.5) +
  theme_bw() + # Use black and white colors
  theme(axis.title.y = element_blank(), # Remove x axis label
        axis.title.x = element_blank(), # Remove y axis label
        strip.placement = "outside", # Use facet labels as y axis label
        strip.background = element_blank(), # Remove facet label background
        legend.title=element_blank(), # Remove legend title
        legend.position = "bottom", # Place legend at bottom
        legend.margin=margin(0,0,0,0),
        legend.box.margin=margin(-10,0,0,0),
        plot.margin = margin(0, 0, 0, 0, "pt"))

ggsave("asylum.tiff", scale = 1, width = 3.25, height = 3.75, units = "in", dpi = 2400)
